Skip to content

[refactor](be) Unify storage reader column ordinals - #66472

Open
csun5285 wants to merge 5 commits into
apache:masterfrom
csun5285:refactor/reader-return-columns
Open

[refactor](be) Unify storage reader column ordinals#66472
csun5285 wants to merge 5 commits into
apache:masterfrom
csun5285:refactor/reader-return-columns

Conversation

@csun5285

@csun5285 csun5285 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@csun5285
csun5285 force-pushed the refactor/reader-return-columns branch 2 times, most recently from 6a3b439 to 768a009 Compare August 7, 2026 12:27
@csun5285

csun5285 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 29131 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 768a0090d6d77fef5a40d4a42f3daad744c933f7, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17707	4084	3969	3969
q2	2013	334	195	195
q3	10307	1380	799	799
q4	4683	464	339	339
q5	7510	852	553	553
q6	186	163	141	141
q7	742	808	611	611
q8	9335	1411	1477	1411
q9	5307	4089	4061	4061
q10	6798	1623	1360	1360
q11	504	366	324	324
q12	735	565	439	439
q13	18078	3670	2730	2730
q14	264	266	253	253
q15	q16	730	726	658	658
q17	1001	1077	1009	1009
q18	6508	5615	5534	5534
q19	1178	1250	1153	1153
q20	789	676	558	558
q21	6133	2876	2725	2725
q22	457	381	309	309
Total cold run time: 100965 ms
Total hot run time: 29131 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4927	4543	4590	4543
q2	295	320	207	207
q3	4880	5209	4737	4737
q4	2176	2256	1400	1400
q5	4496	4541	4391	4391
q6	229	186	146	146
q7	1888	1726	1497	1497
q8	2333	2014	1989	1989
q9	7135	6825	6660	6660
q10	4261	4223	3809	3809
q11	512	367	335	335
q12	688	694	492	492
q13	2953	3320	2737	2737
q14	265	278	249	249
q15	q16	672	679	618	618
q17	1221	1208	1199	1199
q18	12174	10958	11683	10958
q19	1105	1065	1084	1065
q20	2186	2190	1900	1900
q21	5170	4605	4522	4522
q22	512	446	414	414
Total cold run time: 60078 ms
Total hot run time: 53868 ms

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 79.00% (79/100) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 158453 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 768a0090d6d77fef5a40d4a42f3daad744c933f7, data reload: false

query5	4319	579	452	452
query6	462	220	227	220
query7	4856	613	345	345
query8	321	169	160	160
query9	8773	3988	3960	3960
query10	452	366	299	299
query11	5847	2202	2033	2033
query12	149	96	94	94
query13	1254	588	423	423
query14	6072	4241	3979	3979
query14_1	3775	3747	3772	3747
query15	206	197	176	176
query16	1004	469	447	447
query17	960	682	529	529
query18	2428	454	321	321
query19	201	180	139	139
query20	105	100	102	100
query21	234	155	135	135
query22	13043	12972	12782	12782
query23	15908	15121	14563	14563
query23_1	14728	14730	14685	14685
query24	7467	1700	1226	1226
query24_1	1253	1219	1199	1199
query25	524	466	356	356
query26	1303	353	216	216
query27	2587	628	375	375
query28	4554	1986	2005	1986
query29	1053	586	467	467
query30	338	260	222	222
query31	1179	1117	1052	1052
query32	109	61	61	61
query33	527	298	234	234
query34	1214	1159	649	649
query35	721	748	624	624
query36	769	772	675	675
query37	159	103	88	88
query38	1831	1746	1663	1663
query39	827	827	803	803
query39_1	794	781	784	781
query40	246	166	145	145
query41	66	71	64	64
query42	98	95	90	90
query43	320	321	277	277
query44	1412	759	760	759
query45	186	179	180	179
query46	1070	1161	743	743
query47	1572	1557	1446	1446
query48	404	396	298	298
query49	573	412	295	295
query50	1041	436	336	336
query51	10747	10767	10807	10767
query52	88	88	82	82
query53	274	280	201	201
query54	303	259	233	233
query55	78	80	69	69
query56	331	324	301	301
query57	1041	975	930	930
query58	316	282	261	261
query59	1539	1601	1372	1372
query60	322	291	275	275
query61	179	183	177	177
query62	395	327	273	273
query63	241	194	200	194
query64	3012	1179	978	978
query65	3900	3817	3793	3793
query66	1842	498	380	380
query67	20056	20028	19936	19936
query68	3392	1642	1051	1051
query69	431	303	274	274
query70	910	799	772	772
query71	370	354	332	332
query72	3232	2827	2320	2320
query73	824	750	459	459
query74	4632	4481	4281	4281
query75	2366	2344	1983	1983
query76	2423	1155	747	747
query77	339	356	277	277
query78	11182	11120	10552	10552
query79	1438	1195	772	772
query80	663	532	469	469
query81	488	338	293	293
query82	629	166	130	130
query83	409	326	306	306
query84	325	163	129	129
query85	938	612	524	524
query86	315	229	216	216
query87	1961	1950	1828	1828
query88	3688	2793	2764	2764
query89	387	316	279	279
query90	1939	190	189	189
query91	202	185	168	168
query92	64	65	56	56
query93	1568	1575	947	947
query94	535	338	311	311
query95	774	488	481	481
query96	1058	834	353	353
query97	2447	2452	2332	2332
query98	196	183	180	180
query99	753	718	605	605
Total cold run time: 244954 ms
Total hot run time: 158453 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 23.85 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 768a0090d6d77fef5a40d4a42f3daad744c933f7, data reload: false

query1	0.00	0.00	0.00
query2	0.09	0.04	0.04
query3	0.25	0.13	0.13
query4	1.62	0.14	0.13
query5	0.23	0.21	0.22
query6	1.17	0.81	0.79
query7	0.04	0.01	0.01
query8	0.06	0.03	0.04
query9	0.37	0.30	0.33
query10	0.57	0.58	0.60
query11	0.18	0.14	0.13
query12	0.18	0.14	0.14
query13	0.46	0.46	0.48
query14	1.00	1.00	0.98
query15	0.60	0.60	0.58
query16	0.33	0.32	0.31
query17	1.14	1.10	1.08
query18	0.22	0.19	0.20
query19	1.98	1.98	1.97
query20	0.02	0.01	0.01
query21	15.44	0.20	0.13
query22	4.96	0.05	0.05
query23	16.36	0.30	0.12
query24	2.95	0.42	0.31
query25	0.12	0.04	0.04
query26	0.72	0.21	0.14
query27	0.04	0.03	0.03
query28	3.57	0.76	0.37
query29	12.52	4.08	3.22
query30	0.27	0.16	0.16
query31	2.76	0.56	0.31
query32	3.22	0.59	0.48
query33	3.18	3.21	3.19
query34	15.58	3.94	3.24
query35	3.27	3.21	3.23
query36	0.54	0.43	0.43
query37	0.09	0.06	0.07
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.17	0.15	0.14
query41	0.09	0.03	0.03
query42	0.03	0.02	0.02
query43	0.05	0.04	0.03
Total cold run time: 96.53 s
Total hot run time: 23.85 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 84.00% (84/100) 🎉
Increment coverage report
Complete coverage report

csun5285 added a commit to csun5285/doris that referenced this pull request Aug 9, 2026
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66472

Problem Summary: The reader-schema refactor renamed storage block and schema APIs, but several BE tests still used the old interfaces. The FE translator test also left row-binlog index replicas behind the partition version, and one DATETIMEV2 fixture omitted its scale. Update these test fixtures so the refactored reader code is compiled and exercised correctly.

### Release note

None

### Check List (For Author)

- Test: Unit Test and build
    - ASAN BE and FE build
    - PhysicalPlanTranslatorTest: 13 tests passed
    - Reader-related BE UT: 71 tests passed
    - clang-format and clang-tidy passed
- Behavior changed: No
- Does this need documentation: No
@csun5285
csun5285 force-pushed the refactor/reader-return-columns branch from 768a009 to aff0dbe Compare August 9, 2026 14:20
@csun5285

csun5285 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@csun5285

csun5285 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Review step was failure (possibly timeout or cancelled)
Workflow run: https://github.com/apache/doris/actions/runs/31318703378

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@csun5285

Copy link
Copy Markdown
Contributor Author

run buildall

@csun5285

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for two P1 correctness/compatibility blockers in the new FE-authored ReadSchema contract.

Critical checkpoints:

  • Goal and tests: The ordinal unification is coherent on most current-FE paths, but the added tests primarily assert descriptor shape; they do not prove lazy scan outcomes or mixed-version execution.
  • Scope: Reviewed the complete 124-file authoritative diff and the upstream/downstream FE scan, BE reader, merge, index, schema-change, compaction, cloud, binlog, snapshot, rowid, and test paths.
  • Concurrency: No new race was substantiated; shared read-schema mutation is copy-before-publish and occurs before rowset-reader context capture.
  • Lifecycle: Delete-predicate suffix construction, reader initialization, segment state sizing, and visible-prefix output boundaries are coherent.
  • Configuration: The lazy bug is reachable under the existing TopN lazy-materialization threshold; no separate configuration/default regression was found.
  • Compatibility: Blocking issue inline: an older FE can send the same accepted execution version while omitting dependencies that this BE now assumes are present.
  • Parallel paths: Query/direct readers, vertical readers, schema change, compaction, cloud, inverted/ANN, and rowid paths were traced; the distinct missed parallel path is lazy scan translation.
  • Conditions: Key/value predicate ordinal binding, TSO predicate creation, condition-cache fencing, and historical delete conditions were checked; no additional issue survived.
  • Test coverage/results: No local build or tests were run, as required by the review environment. Visible CI has successful BE UT (macOS), CheckStyle, Clang Formatter, license, secrets, and dependency checks; other displayed jobs are skipped, and this automated review status is pending until submission.
  • Observability: The ReadSchema profile output is useful and no logging/profile correctness issue was found.
  • Persistence/transactions: The runtime-only schema object does not alter persisted metadata; rowset versions, delete history, snapshot fences, and transaction-facing row images were reviewed.
  • Data writes: Writer, memtable, compaction, and rowid-conversion edits are mechanical ordinal/schema migrations with no substantiated write-path defect.
  • FE/BE variables: be_exec_version=11 does not encode the new tuple-completeness capability, which is the compatibility blocker noted inline.
  • Performance: No clear performance regression was found in the ordinal maps, column state, or reader construction changes.
  • Other issues: Blocking issue inline: lazy translation can remove keys and snapshot/binlog helper slots before BE constructs ReadSchema.

User focus: review_focus.txt contained no additional focus beyond the full PR review.

Review completion: The full-scope and risk-focused passes converged in Round 2 with no unresolved candidates.

.collect(Collectors.toSet());

olapScanNode.updateRequiredSlots(context, scanIds);
preserveMergeSequenceSlots(olapScanNode, scanIds);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve the full storage dependency set for lazy scans

This second pruning pass bypasses the normal calls to preserveStorageSemanticSlots() and preserveExtraStorageKeySlots(). For the new test query, k1/k2 are lazy, so the scan descriptor keeps v1/sequence/rowid but drops the key prefix; BE then builds a ReadSchema with zero key columns and can merge distinct MOR keys as equal. Lazy snapshot/binlog scans similarly lose commit-TSO or TSO/op/before slots and fail initialization. Apply the same two preservation steps used by updateScanSlotsMaterialization before removing tuple slots.

return Status::InternalError("failed to build storage scanner, no materialized slot!");
}

// The FE physical scan tuple is the read-path schema. It already includes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Keep a fallback for plans from older FEs

This assumes every accepted FE plan already carries the new hidden dependencies, but the PR removes the BE-side expansion that older FEs rely on and adds no thrift/version handshake. The immediately prior FE emits the same be_exec_version=11, so its ordinary plans can reach this BE without sequence/map, commit-TSO, or row-binlog helper slots; the BE then silently chooses the wrong MOR winner or fails _init_tso_predicates/init_sequence_map. Retain legacy dependency expansion (with ordinal remapping), or add an explicit plan capability marker before treating the tuple as authoritative.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不兼容旧FE

@csun5285 csun5285 changed the title [Draft](be) Unify storage reader column ordinals [refactor](be) Unify storage reader column ordinals Aug 10, 2026
@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

// merge or union segment iterator
if (is_merge_iterator()) {
auto sequence_loc = -1;
if (_read_context->sequence_id_idx != -1) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sequence_id_idx 这个参数之前是做什么的?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果 sequence_id_idx 是-1,表示不需要根据seq 列排序,如果不是 -1 ,就表示这一列的位置,就找到seq 列,后面排序会用,现在用 use_sequence_column_for_merge_order 表示是不是需要根据 seq 排序。

return Status::RuntimeError("invalid data type");
}
auto column = data_type->create_column();
*block = _read_schema->create_read_block();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我感觉,我们可能确实得在read schema 中,对于struct 列裁剪这种,我们得把它的column 结构改掉。 不能依靠传递一个data type。
否则很多地方如果有人去把tablet column 拿出来,做一些事情,比如创建一个column 似乎结构就不对了

auto column = data_type->create_column();
*block = _read_schema->create_read_block();
auto columns_guard = block->mutate_columns_scoped();
for (auto& column : columns_guard.mutable_columns()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们之前为什么不是在segment iteartor 中把新加的delete dropped column 删掉啊,为啥要传递会这些iterator 中呢

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

就是在segment iteartor 中删掉的,这里是在重置block

@yiguolei

Copy link
Copy Markdown
Contributor

/review

auto storage_format = _opts.tablet_schema->get_inverted_index_storage_format();
for (int i = 0; i < _schema->columns().size(); ++i) {
for (size_t i = 0; i < _schema->num_read_columns(); ++i) {
const TabletColumn* col = _schema->column(i);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在light weight schema change 加列的时候,这个col 实际在当前segment 中不存在,我们怎么处理呢?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new_column_iteator 会返回一个default_column_iterator

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review completed for 495247871d4fd4089ca750c5e0a7d053dd56a3c8 with no new actionable, non-duplicate findings.

Critical checkpoint conclusions:

  • Goal, scope, and tests: The ReadSchema refactor consistently makes the caller-visible scan tuple the storage read-coordinate prefix, with historical delete columns kept as a private suffix. All 144 authoritative changed paths were reviewed. The added BE/FE tests and regression suites exercise nested pruning, historical delete columns, row-binlog projections, sequence-map dependencies, and lazy materialization. Per the review-runner instructions, I did not build or run tests.
  • Concurrency and lifecycle: Per-reader ReadSchema mutation is isolated where sequence maps are initialized, dropped-column descriptors are appended before iterator construction, and cloned LIKE predicates own separate search scratch state. No new shared-state, lifetime, or static-initialization issue was found.
  • Configuration and compatibility: Condition-cache and statistics fast paths are disabled where TSO/delete semantics require row evaluation; TopN lazy materialization is fenced for sequence-map tables. Current-FE/current-BE dependency population is coherent. The old-FE/new-BE dependency gap is already covered by existing review comment 3745935085, so it is not duplicated here; the earlier lazy second-pruning issue in 3745935083 is fixed at this head.
  • Parallel and special paths: Ordinary and lazy scans, selected indexes, local/cloud schema change, horizontal/vertical/segment compaction, sequence and sequence-map merge, APPEND_ONLY/MIN_DELTA/DETAIL binlog reads, snapshot commit TSO, nested complex pruning, ANN/inverted/LIKE predicates, and Variant paths were traced through their consumers. No distinct correctness gap remained.
  • Persistence, transactions, and writes: Historical delete predicates retain UID-based generation identity, binlog BEFORE/AFTER and TSO ordering remain aligned, and compaction/schema-change writers receive only the visible ReadSchema block prefix. The patch adds no new persisted configuration or protocol field.
  • FE/BE contract, performance, and observability: FE preserves all current storage-semantic slots before final pruning, and BE consumes the same tuple ordinals. The remaining descriptor-based sequence check can only reduce predicate-pushdown reachability; it does not change results. Updated counters and failure paths remain adequate for diagnosis.

User focus: no additional review focus was supplied. The full PR was reviewed without extra narrowing.

std::vector<ColumnId> _common_expr_ordinals;
std::vector<ColumnId> _output_ordinals;
// Sparse, ordered execution list for recovering pruned nested children.
std::vector<ColumnId> _lazy_pruned_ordinals;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看了这个注释也不知道这个变量是干啥的啊

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复杂类型的列裁剪需要延迟物化的列

key_range.lower_key != nullptr ? key_range.lower_key->schema() : nullptr;
if (key_range.upper_key != nullptr &&
(key_schema == nullptr ||
key_range.upper_key->schema()->num_read_columns() > key_schema->num_read_columns())) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

它之前是两个key schema的union,但是新的代码,似乎认为是upper 的key schema 会包含lower?感觉这两者之间没什么必然关系

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

两个key schema 长的一样因为

key_schema = key_range.upper_key->schema();
}
if (key_schema == nullptr) {
return Status::OK();
}
if (!_seek_schema) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个代码也很诡异,难道多个key range的schema 都一样?

_seek_block[i] = Schema::get_data_type_ptr(*column_desc)->create_column();
i++;
if (_seek_block.empty()) {
_seek_block.resize(_seek_schema->num_read_columns());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里跟直接调用seek schema create read block 什么区别?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没区别,我后面改下

key_schema = key_range.upper_key->schema();
}
if (key_schema == nullptr) {
return Status::OK();
}
if (!_seek_schema) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果这里认为肯定相等,我们就得加一些检查,防止我们这种假定可能不对,包括之前的lower key的schema和upper key的schema的问题

}
const TabletColumn* col = _seek_schema->column(i);
int32_t read_ordinal = _schema->ordinal_by_column(*col);
if (read_ordinal >= 0 && _column_iterators[read_ordinal] != nullptr) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果read ordinal < 0 怎么杨?

}
std::unique_ptr<ColumnIterator> iter;
RETURN_IF_ERROR(
_segment->new_column_iterator(*col, &iter, &_opts, &_variant_sparse_column_cache));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么没有吧新的iter 放到 _column_iterators 里?

const TabletColumn* col = _seek_schema->column(i);
int32_t read_ordinal = _schema->ordinal_by_column(*col);
if (read_ordinal >= 0 && _column_iterators[read_ordinal] != nullptr) {
_seek_column_iterators[i] = _column_iterators[read_ordinal].get();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

什么时候会出现,这个column iterator 只在seek 里,但是不在_column_iterators 里?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

比如这个key 列查询的时候没有读,这时候就只在seek 里

bool result_true = _check_all_conditions_passed_inverted_index_for_column(cid);
if (result_true) {
_need_read_data_indices[cid] = false;
_column_states[cid].need_read_data = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没懂

@@ -1054,7 +1031,7 @@ Status SegmentIterator::_apply_ann_topn_predicate() {
// reference count of result_column should be 1, so move will not issue any data copy.
virtual_column_iter->prepare_materialization(std::move(result_column), result_row_ids);

_need_read_data_indices[src_cid] = false;
_column_states[src_cid].need_read_data = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以上这堆 need_read_data 都没看懂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里只是名字的替换,之前保存在_need_read_data_indices 中,现在都保存在 column_state. need_read_data 中

@@ -1467,38 +1402,31 @@ bool SegmentIterator::_need_read_data(ColumnId cid) {
// A column can skip data reads when its predicates have already been fully resolved.
// zonemap_always_true_pred_cols is produced only for non-key columns because key columns
// must remain readable for short-key range seeks.
const bool used_by_common_expr =
cid < _is_common_expr_column.size() && _is_common_expr_column[cid];
const bool used_by_common_expr = _column_states[cid].is_common_expr;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果一个 where col1 > 1 and abs(col1) < 100
此时这个col1 既是 predicate 也是common expr 你这个标记怎么办?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

都在

if (_cur_rowid >= num_rows()) {
return Status::OK();
}

for (auto cid : _schema->column_ids()) {
for (uint32_t cid = 0; cid < _schema->num_read_columns(); ++cid) {
if (!_is_active_read_column(cid)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

换成 _column_states[cid].is_predicate() 这个吧

@@ -1791,7 +1710,7 @@ Status SegmentIterator::_lookup_ordinal_from_sk_index(const RowCursor& key, bool
while (start < end) {
rowid_t mid = (start + end) / 2;
RETURN_IF_ERROR(_seek_and_peek(mid));
int cmp = _compare_short_key_with_seek_block(key, key_col_ids);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为啥是输入的所有的cols?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里指的是 upper key 里面带的所有的key

_short_cir_eval_predicate.push_back(predicate);
}
if (predicate->is_runtime_filter()) {
_filter_info_id.push_back(predicate);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个没用了吗

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没用了

auto cid = _schema->column_id(i);
const auto* column_desc = _schema->column(cid);
for (ColumnId i = 0; i < _schema->num_read_columns(); i++) {
if (!_is_active_read_column(i)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

什么时候这个 active 是false?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop column,并且这个segment 不需要执行 delete pred

current_columns[cid] = std::move(*block->get_by_position(i).column).mutate();
current_columns[cid]->reserve(nrows_read_limit);
}
current_columns[i] = std::move(*block->get_by_position(i).column).mutate();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里check 一下,这个block 里的column 的类型,和 它必须是empty

const auto& file_column_type = _storage_name_and_type[i].second;
const auto& expected_type = _schema->data_type(i);
if (_column_states[i].is_predicate()) {
if (current_columns[i].get() == nullptr) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

predicate column 中有2类:

  1. 单纯是delete 的
  2. 还有用户输入的column
    我们不需要跟要返回的block 关联吗?

// Ordered, disjoint column-role lists built once and reused by every batch.
std::vector<ColumnId> _predicate_ordinals;
std::vector<ColumnId> _common_expr_ordinals;
std::vector<ColumnId> _output_ordinals;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里你得举个例子,把这几种ordinal 都解释一下

cid, column_in_block_is_nothing, column_is_normal, current_column_is_nothing);

if (column_in_block_is_nothing || column_is_normal) {
block->replace_by_position(cid, std::move(_current_columns[cid]));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

按照 current_columns[i] = std::move(*block->get_by_position(i).column).mutate(); 这个写法,它不是本来就是在block 里吗?为啥这里还要replace 一下?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看起来这里不用 replace,难道是 column_in_block_is_nothing 的时候需要特别处理?

@@ -2929,10 +2707,10 @@ Status SegmentIterator::_next_batch_internal(Block* block) {
return _process_eof(block);
}

if (_is_need_vec_eval || _is_need_short_eval || _is_need_expr_eval) {
if (has_residual_eval) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

什么是 residual_eval

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要计算expr 或者pred

_sel_rowid_idx.data(), _selected_size));

// step 3.2: read remaining expr column and evaluate it.
if (_is_need_expr_eval) {
// The predicate column contains the remaining expr column, no need second read.
if (_common_expr_column_ids.size() > 0) {
if (!_common_expr_ordinals.empty()) {
SCOPED_RAW_TIMER(&_opts.stats->non_predicate_read_ns);
RETURN_IF_ERROR(_read_columns_by_rowids(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果一列,既是 predicate ordinal,又是 expr ordinal 怎么办?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经在前面 pred 的时候读过,放到 block 里面了,这里的 _common_expr_ordinals 是不包含的

RETURN_IF_ERROR(_convert_to_expected_type(ordinals));
for (auto cid : ordinals) {
DCHECK_LT(cid, _schema->num_block_columns());
block->replace_by_position(cid, std::move(_current_columns[cid]));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们有很多个这个replace 都是啥含义啊,感觉应该是最后返回的时候replace 一次就行

}
for (size_t i = 0; i < block->columns(); i++) {
if (!_column_states[i].is_predicate()) {
block->replace_by_position(i, std::move(_current_columns[i]));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这又来了一波replace,包括之前那个convert,我感觉都是一个事,表达了,当我们要把current columns 的结果,放进block 里这个事

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该是没用的

std::set<std::shared_ptr<const ColumnPredicate>> delete_predicates;
_opts.delete_condition_predicates->get_all_column_predicate(delete_predicates);
for (const auto& predicate : delete_predicates) {
_convert_dict_code_for_predicate_if_necessary_impl(*predicate);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_col_predicates 里不包括 delete 吗

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不包含

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants